<!doctype html>
<html lang="">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>微信管理</title>

  <!-- Disable tap highlight on IE -->
  <meta name="msapplication-tap-highlight" content="no">

  <link href="styles/bootstrap.min.css" rel="stylesheet">
  <link href="styles/login.css" rel="stylesheet">
</head>

<body>
  <!-- Add your site or app content here -->
  <div class="container">

    <form class="form-signin" id='login-form'>
      <h2 class="form-signin-heading">微信管理后台</h2>
      <label for="inputEmail" class="sr-only">用户名</label>
      <input type="email" id="inputEmail" class="form-control" name="login" placeholder="用户名" required autofocus>
      <label for="inputPassword" class="sr-only">密码</label>
      <input type="password" id="inputPassword" name='passwd' class="form-control" placeholder="密码" required>
      <div class="checkbox">
        <label>
            <input type="checkbox" value="1" name="remember"> 记住我
          </label>
      </div>
      <a class="btn btn-lg btn-primary btn-block" onclick="login()">登录</a>
    </form>

  </div>
  <!-- /container -->

  <!-- Built with love using Web Starter Kit -->
  <script src="scripts/pace.min.js"></script>
  <script src="scripts/jquery.min.js"></script>
  <script src="scripts/bootstrap.min.js"></script>
  <script src="scripts/config.js"></script>
  <script>
    function login() {
      $.post(server_host + '/user/status', $('#login-form').serialize(), function(data) {
        if (data.info.code == 200) {
          //写入用户信息
          sessionStorage.setItem('uid', data.item.uid);
          sessionStorage.setItem('role', data.item.role);
          sessionStorage.setItem('username', data.item.username);
          window.location.href = '/';
        } else {
          alert(data.info.codeMessage);
        }
      }, 'json')
    }
    //检测是否登录
    if (sessionStorage.getItem('uid')) {
      window.location.href = '/';
    }
  </script>
</body>

</html>